<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="myschool.mybatisUtil.MybatisUtil" %>
<%@ page import="myschool.dao.SubjectDao" %>
<%@ page import="myschool.entity.Subject" %>
<%@ page import="java.util.List" %>
<%@ page import="myschool.entity.Grade" %>
<%@ page import="myschool.dao.GradeDao" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/6/6
  Time: 17:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    SqlSession s= MybatisUtil.get();
    SubjectDao mapper = s.getMapper(SubjectDao.class);
    //List<Subject> subjects = mapper.findAll();
    String subId = request.getParameter("subjectId");
    Subject subject = mapper.gets(Long.parseLong(subId));
    MybatisUtil.close(s);
%>
<%
    SqlSession s2= MybatisUtil.get();
    GradeDao mapper2 = s2.getMapper(GradeDao.class);
    List<Grade> grades = mapper2.findAll();
    MybatisUtil.close(s2);
%>
<form action="doChangeSubject.jsp" method="post">
    <div>
        <input type="text" name="id" value="<%=subId%>" hidden>
    </div>
    <div>
        <input type="text" name="newSubjectName" value="<%= subject.getSubjectname() %>">
    </div>
    <div>
        <input type="number" name="classHour" value="<%= subject.getClasshour() %>">
    </div>
    <div>
        <select name="gradeID">
            <%
                for (Grade grade : grades) {
                    if (subject.getGradeid()==grade.getId()){
            %>
            <option value="<%=grade.getId()%>" selected><%=grade.getGname()%></option>
            <%
                        continue;
                    }
            %>
            <option value="<%=grade.getId()%>"><%=grade.getGname()%></option>
            <%
            }
          %>
        </select>
    </div>
    <div>
        <input type="submit" value="修改">
    </div>
</form>
</body>
</html>
